package org.common4j2ee.s2shs.service.user;


import java.util.List;

import org.common4j2ee.s2shs.dao.user.ResourcesDaoImpl;
import org.common4j2ee.s2shs.dao.utils.Page;
import org.common4j2ee.s2shs.dao.utils.PropertyFilter;
import org.common4j2ee.s2shs.entity.user.Resources;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


@Component
@Transactional
public class ResourcesManager {

	@Autowired
	private ResourcesDaoImpl resourcesDao;

	@Transactional(readOnly = true)
	public Page<Resources> searchResources(final Page<Resources> page,
			final List<PropertyFilter> filters) {
		return resourcesDao.findPage(page, filters);
	}
	
	public void deleteResources(Long id) {
		resourcesDao.delete(id);
	}
	
	public List<Resources> getAllResourceList() {
		return resourcesDao.getAll();
	}
	
	public Resources getAuthority(Long id) {
		return resourcesDao.get(id);
	}
	
	@Transactional(readOnly = true)
	public boolean isRoleNameUnique(String ResourceName, String ResourceMenuName) {
		return resourcesDao.isPropertyUnique("name", ResourceName, ResourceMenuName);
	}
	
	public void saveAuthority(Resources entity) {
		entity.setEnabled(1);
		entity.setPriority(1);
		entity.setType("1");
		resourcesDao.save(entity);
	}
}
